﻿<UserControl x:Class="Core.Views.Controls.SysGroupeView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:enums="clr-namespace:Interfaces.Enums;assembly=Interfaces"
             xmlns:class="clr-namespace:Core.Class"
             xmlns:helpers="clr-namespace:Helpers;assembly=Helpers">
    <UserControl.Resources>
        
        <Style x:Key="TreeViewRights" TargetType="{x:Type TreeView}">
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="ItemContainerStyle">
                <Setter.Value>
                    <Style TargetType="{x:Type TreeViewItem}">
                        <Setter Property="TreeViewItem.IsExpanded" Value="True"/>
                    </Style>
                </Setter.Value>
            </Setter>
        </Style>

        <DataTemplate x:Key="RightDefault">
            <Grid Margin="0,5,0,5" HorizontalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="300" />
                    <ColumnDefinition Width="40" />
                    <ColumnDefinition Width="40" />
                    <ColumnDefinition Width="40" />
                </Grid.ColumnDefinitions>
                <TextBlock Text="{Binding Droit.LibelleDroit}" TextWrapping="Wrap" FontSize="9pt" Grid.Column="0" />
                <CheckBox Content="{helpers:Localize Droits_Visualiser}" IsChecked="{Binding ValueTemp, Mode=TwoWay, Converter={StaticResource ValueRightsEnumToBoolConverter}, ConverterParameter={x:Static enums:ValueRightsEnum.Visualisation}}" Grid.Column="1" HorizontalAlignment="Center" />
                <CheckBox Content="{helpers:Localize Droits_Modifier}" IsChecked="{Binding ValueTemp, Mode=TwoWay, Converter={StaticResource ValueRightsEnumToBoolConverter}, ConverterParameter={x:Static enums:ValueRightsEnum.Modification}}" Grid.Column="2" HorizontalAlignment="Center" />
                <CheckBox Content="{helpers:Localize Droits_Supprimer}" IsChecked="{Binding ValueTemp, Mode=TwoWay, Converter={StaticResource ValueRightsEnumToBoolConverter}, ConverterParameter={x:Static enums:ValueRightsEnum.Suppression}}" Grid.Column="3" HorizontalAlignment="Center" />
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="RightSingle">
            <Grid Margin="0,5,0,5" HorizontalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="300" />
                    <ColumnDefinition Width="40" />
                    <ColumnDefinition Width="40" />
                    <ColumnDefinition Width="40" />
                    <ColumnDefinition Width="40" />
                </Grid.ColumnDefinitions>
                <TextBlock Text="{Binding Droit.LibelleDroit}" TextWrapping="Wrap" FontSize="9pt" Grid.Column="0" />
                <CheckBox Content="{helpers:Localize Droits_SimpleFonction}" IsChecked="{Binding ValueTemp, Mode=TwoWay, Converter={StaticResource ValueRightsEnumToBoolConverter}, ConverterParameter={x:Static enums:ValueRightsEnum.Visualisation}}" Grid.Column="1" Grid.ColumnSpan="4" HorizontalAlignment="Left" Margin="5,0,0,0" />
            </Grid>
        </DataTemplate>
        <class:RightTemplateSelector x:Key="RightTemplateSelector" DefaultTemplate="{StaticResource RightDefault}" SingleTemplate="{StaticResource RightSingle}" />
        
        <DataTemplate x:Key="TemplateUsersListBoxItem">
            <CheckBox Content="{Binding Utilisateur.FullName}" IsChecked="{Binding IsChecked, Mode=TwoWay}" />
        </DataTemplate>
        
    </UserControl.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="70" />
            <RowDefinition Height="70" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <!-- Code -->
        <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Vertical" Width="200" Margin="10,10,0,0" HorizontalAlignment="Left">
            <Label Content="{helpers:Localize Groupe_Code}" Style="{DynamicResource LabelOutilParameters}" />
            <TextBox Text="{Binding Groupe.Code, Mode=TwoWay}" Margin="5,2,0,0" HorizontalAlignment="Stretch"/>
        </StackPanel>

        <!-- Libelle -->
        <StackPanel Grid.Row="0" Grid.Column="1" Orientation="Vertical" Width="200" Margin="10,10,0,0" HorizontalAlignment="Left">
            <Label Content="{helpers:Localize Groupe_Libelle}" Style="{DynamicResource LabelOutilParameters}" />
            <TextBox Text="{Binding Groupe.Nom, Mode=TwoWay}" Margin="5,2,0,0" HorizontalAlignment="Stretch"/>
        </StackPanel>

        <!-- Options -->
        <StackPanel Orientation="Vertical" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2" Margin="20,30,0,0">
            <TextBlock Text="{helpers:Localize Groupe_Options}" Foreground="{DynamicResource ColorThemeBrush}" />
            <Line X1="0" X2="1" Y1="0" Y2="0" Stretch="Fill" Stroke="{DynamicResource ColorThemeBrush}" StrokeThickness="1" Margin="0,5,20,0" />
            <Grid Margin="0,15,0,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                
                <!-- Utilisateurs présents -->
                <StackPanel Orientation="Vertical" Grid.Column="0">
                    <TextBlock Text="{helpers:Localize Groupe_UsersInGroupe}" FontSize="9pt" Width="250" TextWrapping="Wrap" HorizontalAlignment="Left"/>
                    <ListBox ItemsSource="{Binding UsersIncludeInGroupes}" Style="{StaticResource ListBoxBorderLightGrayWithItemsTransparent}" Height="100" Margin="0,10,20,0" ItemTemplate="{StaticResource TemplateUsersListBoxItem}"/>
                </StackPanel>

                <!-- Utilisateurs référents -->
                <StackPanel Orientation="Vertical" Grid.Column="1">
                    <TextBlock Text="{helpers:Localize Groupe_UsersReferent}" FontSize="9pt" Width="250" TextWrapping="Wrap" HorizontalAlignment="Left"/>
                    <ListBox ItemsSource="{Binding UsersReferent}" Style="{StaticResource ListBoxBorderLightGrayWithItemsTransparent}" Height="100" Margin="0,10,20,0" ItemTemplate="{StaticResource TemplateUsersListBoxItem}"/>
                </StackPanel>
            </Grid>
        </StackPanel>

        <!-- Droits -->
        <Grid Grid.Column="2" Grid.Row="0" Grid.RowSpan="3" Margin="40,0,0,20">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <StackPanel Orientation="Vertical" Grid.Column="0" Margin="20,10,20,0">
                <TextBlock Text="{helpers:Localize Droits_LabelGroupe}" Foreground="{DynamicResource ColorThemeBrush}" />
                <Line X1="0" X2="1" Y1="0" Y2="0" Stretch="Fill" Stroke="{DynamicResource ColorThemeBrush}" StrokeThickness="1" Margin="0,5,0,0" />

                <TreeView ItemsSource="{Binding DroitsGroupe}" Style="{StaticResource TreeViewRights}" Margin="0,10,0,0" Height="400">
                    <TreeView.ItemTemplate>
                        <HierarchicalDataTemplate ItemsSource="{Binding Droits}" ItemTemplateSelector="{StaticResource RightTemplateSelector}">
                            <TextBlock Text="{Binding Header}" FontSize="11pt" />
                        </HierarchicalDataTemplate>
                    </TreeView.ItemTemplate>
                </TreeView>
            </StackPanel>
        </Grid>
        
        <!-- Validation -->
        <Border Margin="0,40,0,0" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Stretch"  Background="{DynamicResource ColorSeparatorChildWindowBrush}" Height="70">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,10,0" VerticalAlignment="Center">
                <Button Content="{helpers:Localize Generic_Valider}" Command="{Binding SaveCommand}"/>
                <Button Content="{helpers:Localize Generic_Annuler}" Command="{Binding CloseCommand}" />
            </StackPanel>
        </Border>
    </Grid>
</UserControl>
